import { Between, Like } from 'typeorm';

export function handleSql<T>(obj: T) {
  const result = {};
  Object.keys(obj).forEach((key) => {
    if (key === 'create_time' || key === 'update_time') {
      try {
        result[key] = Between(obj[key][0], obj[key][1]);
      } catch (e) {
        throw new Error(e);
      }
    } else {
      result[key] = Like(`%${obj[key]}%`);
    }
  });
  return result;
}
